<?php
/**
 * Description
 *
 * PHP Version 5.6
 *
 * @category TelegramPostBot
 * @package  Data
 * @author   ctwj <908504609@qq.com>
 * @license  MIT https://mit-license.org/
 * @link     https://mit-license.org/
 * @date     2018-12-21 10:48:21
 * @modifyby ctwj
 */

namespace Telegram\Data;

/**
 * Message class
 *
 * 消息
 *
 * @category PHP
 * @package  Data
 * @author   ctwj <908504609@qq.com>
 * @license  MIT https://mit-license.org/
 * @link     MIT https://mit-license.org/
 */
class ResourceModel extends BaseModel
{

    /**
     * 构造函数
     *
     * @param [type] $c Container
     *
     * @return void
     */
    public function __construct($c)
    {
        $this->table = $this->tableName('resource');
        parent::__construct($c);
    }

    /**
     * 跟新资源
     *
     * @param [Telegram\Object\Resource] $resource 资源
     *
     * @return integer
     */
    public function updateResource($resource)
    {
        return $this->update($resource->getArray(), ['id' => $resource->id]);
    }

    /**
     * Get All Active Resource //TODO Active Status
     *
     * @param [Telegram\Object\Resource] $resource 资源
     *
     * @return integer
     */
    public function getAllActiveResource()
    {
        $data = $this->find(
            [
                'id', 'type', 'name', 'url', 'target', 'extinfo[Object]', 'frequency[Int]',
                'message_count[Int]', 'last_time', 'user_id', 'ins_time'
            ],
            [
                'ORDER'     => ['id' => 'ASC']
            ]
        );
        return $data;
    }
}
